package com.buildings.activity.table;

import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.buildings.R;
import com.buildings.api.Api;
import com.buildings.api.Constant;
import com.buildings.base.BaseActivity;
import com.buildings.base.BaseApplication;
import com.buildings.base.JsonBean;
import com.buildings.bean.FaultSvyPointDbEntity;
import com.buildings.bean.FaultSvyPointEntity;
import com.buildings.bean.FaultTypeBean;
import com.buildings.bean.GeologicalSvyPlanningLineDbEntity;
import com.buildings.bean.LoginBean;
import com.buildings.http.BaseCallBack;
import com.buildings.http.JsonBuilder;
import com.buildings.http.MyHttpClient;
import com.buildings.util.CustomToast;
import com.buildings.util.DialogUtils;
import com.buildings.util.FileUtil;
import com.buildings.util.HYDialogUtils;
import com.buildings.util.HYImageUtils;
import com.buildings.util.PhotoRecycleBuild;
import com.buildings.util.SPUtil;
import com.buildings.util.StringUtil;
import com.buildings.util.TabTitleBuilder;
import com.buildings.view.ShowBottomDialog;
import com.google.gson.Gson;
import com.zr.earthquate.db.greendao.DaoSession;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import androidx.annotation.Nullable;
import androidx.recyclerview.widget.RecyclerView;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import okhttp3.Call;

//断层观测点-点
public class FaultSvyPointActivity extends BaseActivity {
    @BindView(R.id.ll_tab_title)
    LinearLayout llTabTitle;
    @BindView(R.id.rv_pics)
    RecyclerView rvPics;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.tv_right_text)
    TextView tvRightText;
    @BindView(R.id.et_id)
    EditText etId;
    @BindView(R.id.et_geologicalsvypointid)
    EditText etGeologicalsvypointid;
    @BindView(R.id.et_fieldid)
    EditText etFieldid;
    @BindView(R.id.et_faultstrike)
    EditText etFaultstrike;
    @BindView(R.id.et_measurefaultdip)
    EditText etMeasurefaultdip;
    @BindView(R.id.et_faultclination)
    EditText etFaultclination;
    @BindView(R.id.tv_feature)
    TextView tvFeature;
    @BindView(R.id.et_verticaldisplacement)
    EditText etVerticaldisplacement;
    @BindView(R.id.et_horizentaloffset)
    EditText etHorizentaloffset;
    @BindView(R.id.et_tensionaldisplacement)
    EditText etTensionaldisplacement;
    @BindView(R.id.et_photoAiid)
    EditText etPhotoAiid;
    @BindView(R.id.tv_photoviewingto)
    TextView tvPhotoviewingto;
    @BindView(R.id.et_photographer)
    EditText etPhotographer;
    @BindView(R.id.ll_visibile)
    LinearLayout llVisibile;
    @BindView(R.id.et_targetfaultid)
    EditText etTargetfaultid;
    @BindView(R.id.tv_targetfaultsource)
    TextView tvTtargetfaultsource;
    @BindView(R.id.et_targetfaultname)
    EditText etTargetfaultname;
    @BindView(R.id.et_scale)
    EditText etScale;
    @BindView(R.id.et_verticaldisplacementerror)
    EditText etVerticaldisplacementerror;
    @BindView(R.id.et_horizentaloffseterror)
    EditText etHorizentaloffseterror;
    @BindView(R.id.et_tensionaldisplacementerror)
    EditText etTensionaldisplacementerror;
    @BindView(R.id.et_datasource)
    EditText etDatasource;
    @BindView(R.id.et_samplecount)
    EditText etSamplecount;
    @BindView(R.id.tv_ismodifyworkmap)
    TextView tvIsmodifyworkmap;
    @BindView(R.id.et_datingsamplecount)
    EditText etDatingsamplecount;
    @BindView(R.id.et_isinmap)
    TextView etIsinmap;
    @BindView(R.id.et_lastangle)
    EditText etLastangle;
    @BindView(R.id.et_remark)
    EditText etRemark;
    @BindView(R.id.btn_submit)
    Button btnSubmit;
    @BindView(R.id.tv_visibile)
    TextView tvVisibile;
    private TabTitleBuilder tabTitleBuilder;
    private PhotoRecycleBuild photoRecycleBuild;
    private Dialog myDialog;

    //断层性质数据
    private List<FaultTypeBean.DataBean> dataBeans = new ArrayList<>();
    //断层性质选中的数据
    private FaultTypeBean.DataBean dataBean;
    //照片镜向选中的数据
    private FaultTypeBean.DataBean directionBean;
    //目标断层来源中的数据
    private FaultTypeBean.DataBean targetfaultsource;

    private DaoSession daoSession;

    private FaultSvyPointDbEntity faultSvyPointDbEntity;

    private String urlArr;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_faultsvypoint);
        ButterKnife.bind(this);
        daoSession = BaseApplication.getInstance().getDaoSession();
        tabTitleBuilder = new TabTitleBuilder(llTabTitle, this);
        initView();
    }

    private String taskId = "";
    private String projectId = "";
    private String projectName = "";
    private String taskName = "";
    private boolean isOnline;
    private String type;
    private int joninType;
    private String uuid;
    private long _id = -1;

    public void initView() {
        joninType = getIntent().getIntExtra("joninType", 1);
        photoRecycleBuild = new PhotoRecycleBuild(this, rvPics, joninType);
        if (joninType != 2) {
            tvTitle.setText("断层观测点-点");
            tvRightText.setText("保存");
            double x = getIntent().getDoubleExtra("x", 0.0);
            double y = getIntent().getDoubleExtra("y", 0.0);
            type = getIntent().getStringExtra("type");
            taskId = getIntent().getStringExtra("taskId");
            projectName = getIntent().getStringExtra("projectName");
            projectId = getIntent().getStringExtra("projectId");
            taskName = getIntent().getStringExtra("taskName");
            isOnline = getIntent().getBooleanExtra("isOnLine", true);
            if (TextUtils.isEmpty(type)) {
                finish();
            }
            if (isOnline && TextUtils.isEmpty(taskId)) {
                finish();
            }
            if (isOnline && TextUtils.isEmpty(projectId)) {
                finish();
            }
            tabTitleBuilder.setLat(x);
            tabTitleBuilder.setLon(y);
            if (getIntent().hasExtra("_id")) {
                _id = getIntent().getLongExtra("_id", -1);
                setLocalData(_id);
            }
            if (1 == Constant.IS_ON_LINE) {
                btnSubmit.setVisibility(View.VISIBLE);
            } else {
                btnSubmit.setVisibility(View.GONE);
            }
        } else {
            isOnline = getIntent().getBooleanExtra("isOnLine", false);
            if (1 == Constant.IS_ON_LINE) {
                tvTitle.setText("断层观测点-点详情");
                uuid = getIntent().getStringExtra("uuid");
                tabTitleBuilder.setEnabled();
                setEnableFalse();
                getDetailHttp();
                btnSubmit.setVisibility(View.GONE);
            } else {
                tvTitle.setText("断层观测点-点");
                tvRightText.setText("保存");
                uuid = getIntent().getStringExtra("uuid");
                if (getIntent().hasExtra("_id")) {
                    _id = getIntent().getLongExtra("_id", -1);
                    setLocalData(_id);
                }
                btnSubmit.setVisibility(View.GONE);
            }

        }
    }

    public void setLocalData(long a) {
        if (a == -1) {
            return;
        }
        List<FaultSvyPointDbEntity> students = daoSession.loadAll(FaultSvyPointDbEntity.class);
        for (FaultSvyPointDbEntity faultSvyPointDbEntity : students) {
            if (a == faultSvyPointDbEntity.get_id()) {
                setDetail(faultSvyPointDbEntity);
            }
        }
    }

    public void setDetail(FaultSvyPointDbEntity bean) {
        this.faultSvyPointDbEntity = bean;
        tabTitleBuilder.setDetailText(bean.getProvince(), bean.getCity()
                , bean.getArea(), bean.getLat(), bean.getLon(), bean.getTown());

        etId.setText(bean.getId());
        etGeologicalsvypointid.setText(bean.getGeologicalsvypointid() + "");
        etFieldid.setText(bean.getFieldid() + "");
        etFaultstrike.setText(bean.getFaultstrike() + "");
        etMeasurefaultdip.setText(bean.getMeasurefaultdip() + "");
        etFaultclination.setText(bean.getFaultclination() + "");
        tvFeature.setText(bean.getFeatureName() + "");
        etVerticaldisplacement.setText(bean.getVerticaldisplacement() + "");
        etHorizentaloffset.setText(bean.getHorizentaloffset() + "");
        etTensionaldisplacement.setText(bean.getTensionaldisplacement() + "");
        etPhotoAiid.setText(bean.getPhotoAiid() + "");
        tvPhotoviewingto.setText(bean.getPhotoviewingtoName() + "");
        etPhotographer.setText(bean.getPhotographer() + "");
        etTargetfaultid.setText(bean.getTargetfaultid() + "");
        tvTtargetfaultsource.setText(bean.getTtargetfaultsourceName() + "");
        etTargetfaultname.setText(bean.getTargetfaultname() + "");
        etScale.setText(bean.getScale() + "");
        etVerticaldisplacementerror.setText(bean.getVerticaldisplacementerror() + "");
        etHorizentaloffseterror.setText(bean.getHorizentaloffseterror() + "");
        etTensionaldisplacementerror.setText(bean.getTensionaldisplacementerror() + "");
        etDatasource.setText(bean.getDatasource() + "");
        etSamplecount.setText(bean.getSamplecount() + "");
        tvIsmodifyworkmap.setText(bean.getIsmodifyworkmap());
        etDatingsamplecount.setText(bean.getDatingsamplecount() + "");
        etIsinmap.setText(bean.getIsinmap());
        etLastangle.setText(bean.getLastangle() + "");
        etRemark.setText(bean.getCommentInfo() + "");
        if (!TextUtils.isEmpty(bean.getExtends7())) {
            String[] arr = bean.getExtends7().split(",");
            List<Uri> list = new ArrayList<>();
            for (int i = 0; i < arr.length; i++) {
                File file = new File(arr[i]);
                Uri uri = Uri.fromFile(file);
                list.add(uri);
            }
            photoRecycleBuild.updataAdapter(list);
        }
    }

    private void setEnableFalse() {
        etId.setEnabled(false);
        etGeologicalsvypointid.setEnabled(false);
        etFieldid.setEnabled(false);
        etFaultstrike.setEnabled(false);
        etMeasurefaultdip.setEnabled(false);
        etFaultclination.setEnabled(false);
        tvFeature.setEnabled(false);
        etVerticaldisplacement.setEnabled(false);
        etHorizentaloffset.setEnabled(false);
        etTensionaldisplacement.setEnabled(false);
        etPhotoAiid.setEnabled(false);
        tvPhotoviewingto.setEnabled(false);
        etPhotographer.setEnabled(false);
        etTargetfaultid.setEnabled(false);
        tvTtargetfaultsource.setEnabled(false);
        etTargetfaultname.setEnabled(false);
        etScale.setEnabled(false);
        etVerticaldisplacementerror.setEnabled(false);
        etHorizentaloffseterror.setEnabled(false);
        etTensionaldisplacementerror.setEnabled(false);
        etDatasource.setEnabled(false);
        etSamplecount.setEnabled(false);
        tvIsmodifyworkmap.setEnabled(false);
        etDatingsamplecount.setEnabled(false);
        etIsinmap.setEnabled(false);
        etLastangle.setEnabled(false);
        etRemark.setEnabled(false);
    }

    private Gson gson = new Gson();
    ;

    @OnClick({R.id.iv_back, R.id.tv_right_text, R.id.tv_visibile, R.id.tv_feature, R.id.tv_photoviewingto
            , R.id.tv_targetfaultsource, R.id.tv_ismodifyworkmap, R.id.et_isinmap, R.id.iv_faultstrike_hint
            , R.id.iv_measurefaultdip_hint, R.id.iv_faultclination_hint, R.id.btn_submit, R.id.iv_id_hint})
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_back:
                finish();
                break;
            case R.id.iv_faultclination_hint:
                HYDialogUtils.showCommonAlertDialog(this, "角度取值范围0~360"
                        , new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int i) {
                            }
                        });
                break;
            case R.id.iv_measurefaultdip_hint:
                HYDialogUtils.showCommonAlertDialog(this, "角度取值范围0~360"
                        , new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int i) {
                            }
                        });
                break;
            case R.id.iv_faultstrike_hint:
                HYDialogUtils.showCommonAlertDialog(this, "角度取值范围0~360"
                        , new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int i) {
                            }
                        });
                break;
            case R.id.et_isinmap:
                ShowBottomDialog.BottomDialog(this, new ShowBottomDialog.IsSlect() {
                    @Override
                    public void select(boolean b, Dialog dialog) {
                        if (b) {
                            etIsinmap.setText("是");
                        } else {
                            etIsinmap.setText("否");
                        }
                        dialog.dismiss();
                    }
                });
                break;
            case R.id.tv_ismodifyworkmap:
                ShowBottomDialog.BottomDialog(this, new ShowBottomDialog.IsSlect() {
                    @Override
                    public void select(boolean b, Dialog dialog) {
                        if (b) {
                            tvIsmodifyworkmap.setText("是");
                        } else {
                            tvIsmodifyworkmap.setText("否");
                        }
                        dialog.dismiss();
                    }
                });
                break;
            case R.id.tv_targetfaultsource:
//                if (myDialog == null) {
//                    myDialog = DialogUtils.showRefreshDialog(activity);
//                } else {
//                    myDialog.show();
//                }
//                getHttpData("FaultSourceCVD");
                FaultTypeBean faultTypeBean2 = gson.fromJson(JsonBean.FaultSourceCVD, FaultTypeBean.class);
                setFaultTypeCVD(faultTypeBean2, "FaultSourceCVD");
                break;
            case R.id.tv_photoviewingto:
                FaultTypeBean faultTypeBean1 = gson.fromJson(JsonBean.CVD_16_Direction, FaultTypeBean.class);
                setFaultTypeCVD(faultTypeBean1, "CVD-16-Direction");
                break;
            case R.id.tv_feature:
                //断层性质
//                if (myDialog == null) {
//                    myDialog = DialogUtils.showRefreshDialog(activity);
//                } else {
//                    myDialog.show();
//                }
//                getHttpData("FaultTypeCVD");
                FaultTypeBean faultTypeBean = gson.fromJson(JsonBean.FaultTypeCVD, FaultTypeBean.class);
                setFaultTypeCVD(faultTypeBean, "FaultTypeCVD");
                break;
            case R.id.tv_visibile:
                if (llVisibile.getVisibility() == View.VISIBLE) {
                    llVisibile.setVisibility(View.GONE);
                    tvVisibile.setText("显示更多");
                } else {
                    llVisibile.setVisibility(View.VISIBLE);
                    tvVisibile.setText("隐藏更多");
                }
                break;
            case R.id.btn_submit:
                submit();
                break;
            case R.id.tv_right_text:
                //TODO 调用保存表单接口
                save();
                break;
            case R.id.iv_id_hint:
                HYDialogUtils.showCommonAlertDialog(this, "长度17位，前9位，行政区划代码6位+3位专题号，后8位自定义编码，字母数字均可，不足8位#补齐\n" +
                                "3位专题号，用户自己设置。一般就是100，101，102...,201,202"
                        , new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int i) {
                            }
                        });
                break;
        }
    }

    public void save() {
        FaultSvyPointDbEntity faultSvyPointDbEntity = new FaultSvyPointDbEntity();
        if (null == daoSession) {
            daoSession = BaseApplication.getInstance().getDaoSession();
        }
        String province = tabTitleBuilder.getProvinceStr();
        String city = tabTitleBuilder.getCityStr();
        String area = tabTitleBuilder.getAreaStr();
        String lat = tabTitleBuilder.getLatStr();
        String lon = tabTitleBuilder.getLonStr();
        String buildingAddress = tabTitleBuilder.getBuilderAdressStr();

        String id = etId.getText().toString().trim();
        String geologicalsvypointid = etGeologicalsvypointid.getText().toString().trim();
        String fieldid = etFieldid.getText().toString().trim();
        String faultstrike = etFaultstrike.getText().toString().trim();
        String measurefaultdip = etMeasurefaultdip.getText().toString().trim();
        String faultclination = etFaultclination.getText().toString().trim();
        String feature = tvFeature.getText().toString().trim();
        String verticaldisplacement = etVerticaldisplacement.getText().toString().trim();
        String horizentaloffset = etHorizentaloffset.getText().toString().trim();
        String tensionaldisplacement = etTensionaldisplacement.getText().toString().trim();
        String photoAiid = etPhotoAiid.getText().toString().trim();
        String photoviewingto = tvPhotoviewingto.getText().toString().trim();
        String photographer = etPhotographer.getText().toString().trim();
        String targetfaultid = etTargetfaultid.getText().toString().trim();
        String ttargetfaultsource = tvTtargetfaultsource.getText().toString().trim();
        String targetfaultname = etTargetfaultname.getText().toString().trim();
        String scale = etScale.getText().toString().trim();
        String verticaldisplacementerror = etVerticaldisplacementerror.getText().toString().trim();
        String horizentaloffseterror = etHorizentaloffseterror.getText().toString().trim();
        String tensionaldisplacementerror = etTensionaldisplacementerror.getText().toString().trim();
        String datasource = etDatasource.getText().toString().trim();
        String samplecount = etSamplecount.getText().toString().trim();
        String ismodifyworkmap = tvIsmodifyworkmap.getText().toString().trim();
        String datingsamplecount = etDatingsamplecount.getText().toString().trim();
        String isinmap = etIsinmap.getText().toString().trim();
        String lastangle = etLastangle.getText().toString().trim();
        String remark = etRemark.getText().toString().trim();
        if (TextUtils.isEmpty(province)) {
            Toast("请录入地区");
            return;
        }
        if (TextUtils.isEmpty(city)) {
            Toast("请录入地区");
            return;
        }
        if (TextUtils.isEmpty(area)) {
            Toast("请录入地区");
            return;
        }
        if (TextUtils.isEmpty(lon)) {
            Toast("请录入纬度");
            return;
        }
        if (TextUtils.isEmpty(lat)) {
            Toast("请录入经度");
            return;
        }
        if (TextUtils.isEmpty(buildingAddress)) {
            Toast("请录入详细地址");
            return;
        }

        if (TextUtils.isEmpty(id)) {
            Toast("请录入产状点编号");
            return;
        }
        if (id.length() != 17) {
            Toast("请录入正确的产状点编号");
            return;
        }
        if (TextUtils.isEmpty(fieldid)) {
            Toast("请录入观测点野外编号");
            return;
        }
        if (!TextUtils.isEmpty(faultstrike)) {
            double d1 = Double.parseDouble(faultstrike);
            if (d1 < 0 || d1 > 360) {
                Toast("断层走向角度值范围 0 ~ 360");
                return;
            }
        }
        if (!TextUtils.isEmpty(measurefaultdip)) {
            double d2 = Double.parseDouble(measurefaultdip);
            if (d2 < 0 || d2 > 360) {
                Toast("断层倾向角度值范围 0 ~ 360");
                return;
            }
        }
        if (!TextUtils.isEmpty(faultclination)) {
            double d3 = Double.parseDouble(faultclination);
            if (d3 < 0 || d3 > 360) {
                Toast("断层倾角角度值范围 0 ~ 360");
                return;
            }
        }
        faultSvyPointDbEntity.setProvince(province);
        faultSvyPointDbEntity.setCity(city);
        faultSvyPointDbEntity.setArea(area);
        faultSvyPointDbEntity.setLat(lat);
        faultSvyPointDbEntity.setLon(lon);
        faultSvyPointDbEntity.setTown(buildingAddress);
        faultSvyPointDbEntity.setId(id);
        faultSvyPointDbEntity.setGeologicalsvypointid(geologicalsvypointid);
        faultSvyPointDbEntity.setFieldid(fieldid);
        faultSvyPointDbEntity.setFaultstrike(faultstrike);
        faultSvyPointDbEntity.setMeasurefaultdip(measurefaultdip);
        faultSvyPointDbEntity.setFaultclination(faultclination);
        faultSvyPointDbEntity.setFeature(null == dataBean ? null == faultSvyPointDbEntity ? "" : faultSvyPointDbEntity.getFeature() : dataBean.getDictItemCode());
        faultSvyPointDbEntity.setFeatureName(feature);
        faultSvyPointDbEntity.setVerticaldisplacement(verticaldisplacement);
        faultSvyPointDbEntity.setHorizentaloffset(horizentaloffset);
        faultSvyPointDbEntity.setTensionaldisplacement(tensionaldisplacement);
        faultSvyPointDbEntity.setPhotoAiid(photoAiid);
        faultSvyPointDbEntity.setPhotoviewingto(null == directionBean ? null == faultSvyPointDbEntity ? "" : faultSvyPointDbEntity.getPhotoviewingto() : directionBean.getDictItemCode());
        faultSvyPointDbEntity.setPhotoviewingtoName(photoviewingto);
        faultSvyPointDbEntity.setPhotographer(photographer);
        faultSvyPointDbEntity.setTargetfaultid(targetfaultid);
        faultSvyPointDbEntity.setTargetfaultsource(null == targetfaultsource ? null == faultSvyPointDbEntity ? "" : faultSvyPointDbEntity.getTargetfaultsource() : targetfaultsource.getDictItemCode());
        faultSvyPointDbEntity.setTtargetfaultsourceName(ttargetfaultsource);
        faultSvyPointDbEntity.setTargetfaultname(targetfaultname);
        faultSvyPointDbEntity.setScale(scale);
        faultSvyPointDbEntity.setVerticaldisplacementerror(verticaldisplacementerror);
        faultSvyPointDbEntity.setHorizentaloffseterror(horizentaloffseterror);
        faultSvyPointDbEntity.setTensionaldisplacementerror(tensionaldisplacementerror);
        faultSvyPointDbEntity.setDatasource(datasource);
        faultSvyPointDbEntity.setSamplecount(samplecount);
        faultSvyPointDbEntity.setIsmodifyworkmap(ismodifyworkmap);
        faultSvyPointDbEntity.setDatingsamplecount(datingsamplecount);
        faultSvyPointDbEntity.setIsinmap(isinmap);
        faultSvyPointDbEntity.setLastangle(lastangle);
        faultSvyPointDbEntity.setCommentInfo(remark);
        if (Constant.IS_ON_LINE == 1) {
            faultSvyPointDbEntity.setTaskId(taskId);
            faultSvyPointDbEntity.setProjectId(projectId);
            faultSvyPointDbEntity.setProjectName(projectName);
            faultSvyPointDbEntity.setTaskName(taskName);
        }
        if (photoRecycleBuild.getSrcList().size() != 0) {
            String url = "";
            for (int i = 0; i < photoRecycleBuild.getSrcList().size(); i++) {
                if (TextUtils.isEmpty(url)) {
                    url = FileUtil.uriToFile(photoRecycleBuild.getSrcList().get(i), activity).getPath();
                } else {
                    url = url + "," + FileUtil.uriToFile(photoRecycleBuild.getSrcList().get(i), activity).getPath();
                }
            }
            faultSvyPointDbEntity.setExtends7(url);
        }
        if (-1 != _id) {
            faultSvyPointDbEntity.set_id(_id);
        }
        daoSession.insertOrReplace(faultSvyPointDbEntity);

        CustomToast.showToast(this, "保存成功");
        finish();
    }

    public void submit() {
        String province = tabTitleBuilder.getProvinceStr();
        String city = tabTitleBuilder.getCityStr();
        String area = tabTitleBuilder.getAreaStr();
        String lat = tabTitleBuilder.getLatStr();
        String lon = tabTitleBuilder.getLonStr();
        String buildingAddress = tabTitleBuilder.getBuilderAdressStr();

        String id = etId.getText().toString().trim();
        String geologicalsvypointid = etGeologicalsvypointid.getText().toString().trim();
        String fieldid = etFieldid.getText().toString().trim();
        String faultstrike = etFaultstrike.getText().toString().trim();
        String measurefaultdip = etMeasurefaultdip.getText().toString().trim();
        String faultclination = etFaultclination.getText().toString().trim();
        String feature = tvFeature.getText().toString().trim();
        String verticaldisplacement = etVerticaldisplacement.getText().toString().trim();
        String horizentaloffset = etHorizentaloffset.getText().toString().trim();
        String tensionaldisplacement = etTensionaldisplacement.getText().toString().trim();
        String photoAiid = etPhotoAiid.getText().toString().trim();
        String photoviewingto = tvPhotoviewingto.getText().toString().trim();
        String photographer = etPhotographer.getText().toString().trim();
        String targetfaultid = etTargetfaultid.getText().toString().trim();
        String ttargetfaultsource = tvTtargetfaultsource.getText().toString().trim();
        String targetfaultname = etTargetfaultname.getText().toString().trim();
        String scale = etScale.getText().toString().trim();
        String verticaldisplacementerror = etVerticaldisplacementerror.getText().toString().trim();
        String horizentaloffseterror = etHorizentaloffseterror.getText().toString().trim();
        String tensionaldisplacementerror = etTensionaldisplacementerror.getText().toString().trim();
        String datasource = etDatasource.getText().toString().trim();
        String samplecount = etSamplecount.getText().toString().trim();
        String ismodifyworkmap = tvIsmodifyworkmap.getText().toString().trim();
        String datingsamplecount = etDatingsamplecount.getText().toString().trim();
        String isinmap = etIsinmap.getText().toString().trim();
        String lastangle = etLastangle.getText().toString().trim();
        String remark = etRemark.getText().toString().trim();

        if (TextUtils.isEmpty(province)) {
            Toast("请录入地区");
            return;
        }
        if (TextUtils.isEmpty(city)) {
            Toast("请录入地区");
            return;
        }
        if (TextUtils.isEmpty(area)) {
            Toast("请录入地区");
            return;
        }
        if (TextUtils.isEmpty(lon)) {
            Toast("请录入纬度");
            return;
        }
        if (TextUtils.isEmpty(lat)) {
            Toast("请录入经度");
            return;
        }
        if (TextUtils.isEmpty(buildingAddress)) {
            Toast("请录入详细地址");
            return;
        }

        if (TextUtils.isEmpty(id)) {
            Toast("请录入产状点编号");
            return;
        }
        if (id.length() != 17) {
            Toast("请录入正确的产状点编号");
            return;
        }
        if (TextUtils.isEmpty(fieldid)) {
            Toast("请录入观测点野外编号");
            return;
        }
        if (!TextUtils.isEmpty(faultstrike)) {
            double d1 = Double.parseDouble(faultstrike);
            if (d1 < 0 || d1 > 360) {
                Toast("断层走向角度值范围 0 ~ 360");
                return;
            }
        }
        if (!TextUtils.isEmpty(measurefaultdip)) {
            double d2 = Double.parseDouble(measurefaultdip);
            if (d2 < 0 || d2 > 360) {
                Toast("断层倾向角度值范围 0 ~ 360");
                return;
            }
        }
        if (!TextUtils.isEmpty(faultclination)) {
            double d3 = Double.parseDouble(faultclination);
            if (d3 < 0 || d3 > 360) {
                Toast("断层倾角角度值范围 0 ~ 360");
                return;
            }
        }
        if (myDialog == null) {
            myDialog = DialogUtils.showRefreshDialog(activity);
        } else {
            myDialog.show();
        }
        DialogUtils.showIOSDialog(activity, "提示", "", "", "", ""
                , new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (null != myDialog)
                            myDialog.dismiss();
                    }
                }, new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        photoRecycleBuild.submitImage(photoRecycleBuild.getSrcList(), 1, new PhotoRecycleBuild.ImageCallBack() {
                            @Override
                            public void onCallBack(String url) {
                                FaultSvyPointActivity.this.urlArr = url;

                                JsonBuilder jsonBuilder = new JsonBuilder(FaultSvyPointActivity.this);
                                jsonBuilder.put("province", province);
                                jsonBuilder.put("city", city);
                                jsonBuilder.put("area", area);
                                jsonBuilder.put("lat", lon);
                                jsonBuilder.put("lon", lat);
                                jsonBuilder.put("town", buildingAddress);
                                jsonBuilder.put("type", type);
                                jsonBuilder.put("taskId", taskId);
                                jsonBuilder.put("projectId", projectId);
                                jsonBuilder.put("projectName", projectName);
                                jsonBuilder.put("taskName", taskName);
                                jsonBuilder.put("userId", SPUtil.get("userId", ""));
                                jsonBuilder.put("id", id);
                                jsonBuilder.put("geologicalsvypointid", geologicalsvypointid);
                                jsonBuilder.put("fieldid", fieldid);
                                jsonBuilder.put("faultstrike", faultstrike);
                                jsonBuilder.put("measurefaultdip", measurefaultdip);
                                jsonBuilder.put("faultclination", faultclination);
                                jsonBuilder.put("verticaldisplacement", verticaldisplacement);
                                jsonBuilder.put("horizentaloffset", horizentaloffset);
                                jsonBuilder.put("tensionaldisplacement", tensionaldisplacement);
                                jsonBuilder.put("photoAiid", photoAiid);
                                jsonBuilder.put("photographer", photographer);
                                jsonBuilder.put("targetfaultid", targetfaultid);
                                jsonBuilder.put("targetfaultname", targetfaultname);
                                jsonBuilder.put("scale", scale);
                                jsonBuilder.put("verticaldisplacementerror", verticaldisplacementerror);
                                jsonBuilder.put("horizentaloffseterror", horizentaloffseterror);
                                jsonBuilder.put("tensionaldisplacementerror", tensionaldisplacementerror);
                                jsonBuilder.put("datasource", datasource);
                                jsonBuilder.put("samplecount", samplecount);
                                jsonBuilder.put("ismodifyworkmap", "是".equals(ismodifyworkmap) ? 1 : 0);
                                jsonBuilder.put("datingsamplecount", datingsamplecount);
                                jsonBuilder.put("isinmap", "是".equals(isinmap) ? 1 : 0);
                                jsonBuilder.put("lastangle", lastangle);
                                jsonBuilder.put("commentInfo", remark);
                                jsonBuilder.put("extends7", urlArr);
                                jsonBuilder.put("createUser", SPUtil.get("userId", ""));
                                if (null == faultSvyPointDbEntity) {
                                    jsonBuilder.put("feature", null == dataBean ? "" : dataBean.getDictItemCode());
                                    jsonBuilder.put("featureName", null == dataBean ? "" : dataBean.getDictItemName());
                                    jsonBuilder.put("photoviewingto", null == directionBean ? "" : directionBean.getDictItemCode());
                                    jsonBuilder.put("photoviewingtoName", null == directionBean ? "" : directionBean.getDictItemName());
                                    jsonBuilder.put("targetfaultsource", null == targetfaultsource ? "" : targetfaultsource.getDictItemCode());
                                    jsonBuilder.put("targetfaultsourceName", null == targetfaultsource ? "" : targetfaultsource.getDictItemName());
                                } else {
                                    jsonBuilder.put("feature", faultSvyPointDbEntity.getFeature());
                                    jsonBuilder.put("featureName", faultSvyPointDbEntity.getFeatureName());
                                    jsonBuilder.put("photoviewingto", faultSvyPointDbEntity.getPhotoviewingto());
                                    jsonBuilder.put("photoviewingtoName", faultSvyPointDbEntity.getPhotoviewingtoName());
                                    jsonBuilder.put("targetfaultsource", faultSvyPointDbEntity.getTargetfaultsource());
                                    jsonBuilder.put("targetfaultsourceName", faultSvyPointDbEntity.getTargetfaultsourceName());
                                }

                                MyHttpClient
                                        .newBuilder()
                                        .post()
                                        .url(Api.DZDCGHLX_SAVE)
                                        .addParam(jsonBuilder.toJsonString())
                                        .build()
                                        .enqueue(new BaseCallBack<LoginBean>() {
                                            @Override
                                            public void onSuccess(LoginBean bean) {
                                                super.onSuccess(bean);
                                                if (bean.getCode() == 200) {
                                                    if (-1 != _id && null != faultSvyPointDbEntity) {
                                                        try {
                                                            daoSession.delete(faultSvyPointDbEntity);
                                                        } catch (Exception e) {
                                                            e.printStackTrace();
                                                        }
                                                    }
                                                    CustomToast.showToast(FaultSvyPointActivity.this, "提交成功");
                                                    finish();
                                                }
                                                if (myDialog != null)
                                                    myDialog.dismiss();
                                            }

                                            @Override
                                            public void onFailure(Call call, IOException e) {
                                                super.onFailure(call, e);
                                                if (myDialog != null)
                                                    myDialog.dismiss();
                                                CustomToast.showToast(FaultSvyPointActivity.this, "网络异常");
                                            }

                                            @Override
                                            public void onError(int code) {
                                                super.onError(code);
                                                if (myDialog != null)
                                                    myDialog.dismiss();
                                                CustomToast.showToast(FaultSvyPointActivity.this, "网络异常");
                                            }
                                        });
                            }
                        });
                    }
                }, "提交后不能再修改");
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode != RESULT_OK) {
            return;
        }
        switch (requestCode) {
            case HYImageUtils.REQUEST_CODE_FROM_CAMERA:
                List<Uri> list_1 = new ArrayList<>();
                list_1.add(HYImageUtils.imageUriFromCamera);
                photoRecycleBuild.updataAdapter(list_1);
                break;
            case HYImageUtils.REQUEST_CODE_FROM_ALBUM:
                ArrayList<String> files = data.getStringArrayListExtra("files");
                if (files == null || files.size() == 0) {
                    return;
                }
                List<Uri> list_2 = new ArrayList<>();
                for (String file : files) {
                    list_2.add(Uri.fromFile(new File(file)));
                }
                photoRecycleBuild.updataAdapter(list_2);
                // submitImage(list_2, correctTypeListEntity.getFieldList().get(lastClickItemPosition));
                break;
        }
    }

    private void getHttpData(String type) {
        MyHttpClient
                .newBuilder()
                .get()
                .url(Api.DCGCD_DICT + type)
                .build()
                .enqueue(new BaseCallBack<FaultTypeBean>() {
                    @Override
                    public void onSuccess(FaultTypeBean bean) {
                        super.onSuccess(bean);
                        if (bean.getCode() == 200) {
                            setFaultTypeCVD(bean, type);
                        }
                        if (myDialog != null)
                            myDialog.dismiss();
                    }

                    @Override
                    public void onFailure(Call call, IOException e) {
                        super.onFailure(call, e);
                        if (myDialog != null)
                            myDialog.dismiss();
                        CustomToast.showToast(FaultSvyPointActivity.this, "网络异常");
                    }

                    @Override
                    public void onError(int code) {
                        super.onError(code);
                        if (myDialog != null)
                            myDialog.dismiss();
                        CustomToast.showToast(FaultSvyPointActivity.this, "网络异常");
                    }
                });
    }


    public void setFaultTypeCVD(FaultTypeBean bean, String type) {
        dataBeans.clear();
        dataBeans.addAll(bean.getData());
        String[] arr = new String[dataBeans.size()];
        for (int i = 0; i < dataBeans.size(); i++) {
            arr[i] = dataBeans.get(i).getDictItemName();
        }
        HYDialogUtils.showSingleChoiceItemAlertDialog(this, "选择", 0, arr
                , new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        switch (type) {
                            case "FaultTypeCVD":
                                dataBean = dataBeans.get(i);
                                tvFeature.setText(dataBeans.get(i).getDictItemName());
                                break;
                            case "CVD-16-Direction":
                                directionBean = dataBeans.get(i);
                                tvPhotoviewingto.setText(dataBeans.get(i).getDictItemName());
                                break;
                            case "FaultSourceCVD":
                                targetfaultsource = dataBeans.get(i);
                                tvTtargetfaultsource.setText(dataBeans.get(i).getDictItemName());
                                break;
                        }
                        dialogInterface.dismiss();
                    }
                });
    }

    public void getDetailHttp() {
        if (myDialog == null) {
            myDialog = DialogUtils.showRefreshDialog(activity);
        } else {
            myDialog.show();
        }
        String url = Api.DZDCGHLX_SAVE + "/" + uuid;
        MyHttpClient
                .newBuilder()
                .get()
                .url(url)
                .build()
                .enqueue(new BaseCallBack<FaultSvyPointEntity>() {
                    @Override
                    public void onSuccess(FaultSvyPointEntity bean) {
                        super.onSuccess(bean);
                        if (bean.getCode() == 200) {
                            setDetailData(bean);
                        }
                        if (myDialog != null)
                            myDialog.dismiss();
                    }

                    @Override
                    public void onFailure(Call call, IOException e) {
                        super.onFailure(call, e);
                        if (myDialog != null)
                            myDialog.dismiss();
                        CustomToast.showToast(FaultSvyPointActivity.this, "网络异常");
                    }

                    @Override
                    public void onError(int code) {
                        super.onError(code);
                        if (myDialog != null)
                            myDialog.dismiss();
                        CustomToast.showToast(FaultSvyPointActivity.this, "网络异常");
                    }
                });
    }

    private void setDetailData(FaultSvyPointEntity bean) {
        tabTitleBuilder.setDetailText(bean.getData().getProvince(), bean.getData().getCity()
                , bean.getData().getArea(), bean.getData().getLat(), bean.getData().getLon(), bean.getData().getTown());

        etId.setText(StringUtil.isNull(bean.getData().getId()));
        etGeologicalsvypointid.setText(StringUtil.isNull(bean.getData().getGeologicalsvypointid() + ""));
        etFieldid.setText(StringUtil.isNull(bean.getData().getFieldid() + ""));
        etFaultstrike.setText(StringUtil.isNull(bean.getData().getFaultstrike() + ""));
        etMeasurefaultdip.setText(StringUtil.isNull(bean.getData().getMeasurefaultdip() + ""));
        etFaultclination.setText(StringUtil.isNull(bean.getData().getFaultclination() + ""));
        tvFeature.setText(StringUtil.isNull(bean.getData().getFeatureName() + ""));
        etVerticaldisplacement.setText(StringUtil.isNull(bean.getData().getVerticaldisplacement() + ""));
        etHorizentaloffset.setText(StringUtil.isNull(bean.getData().getHorizentaloffset() + ""));
        etTensionaldisplacement.setText(StringUtil.isNull(bean.getData().getTensionaldisplacement() + ""));
        etPhotoAiid.setText(StringUtil.isNull(bean.getData().getPhotoAiid() + ""));
        tvPhotoviewingto.setText(StringUtil.isNull(bean.getData().getPhotoviewingtoName() + ""));
        etPhotographer.setText(StringUtil.isNull(bean.getData().getPhotographer() + ""));
        etTargetfaultid.setText(StringUtil.isNull(bean.getData().getTargetfaultid() + ""));
        tvTtargetfaultsource.setText(StringUtil.isNull(bean.getData().getTargetfaultsourceName() + ""));
        etTargetfaultname.setText(StringUtil.isNull(bean.getData().getTargetfaultname() + ""));
        etScale.setText(StringUtil.isNull(bean.getData().getScale() + ""));
        etVerticaldisplacementerror.setText(StringUtil.isNull(bean.getData().getVerticaldisplacementerror() + ""));
        etHorizentaloffseterror.setText(StringUtil.isNull(bean.getData().getHorizentaloffseterror() + ""));
        etTensionaldisplacementerror.setText(StringUtil.isNull(bean.getData().getTensionaldisplacementerror() + ""));
        etDatasource.setText(StringUtil.isNull(bean.getData().getDatasource() + ""));
        etSamplecount.setText(StringUtil.isNull(bean.getData().getSamplecount() + ""));
        tvIsmodifyworkmap.setText("1".equals(bean.getData().getIsmodifyworkmap()) ? "是" : "否");
        etDatingsamplecount.setText(StringUtil.isNull(bean.getData().getDatingsamplecount() + ""));
        etIsinmap.setText("1".equals(bean.getData().getIsinmap()) ? "是" : "否");
        etLastangle.setText(StringUtil.isNull(bean.getData().getLastangle() + ""));
        etRemark.setText(StringUtil.isNull(bean.getData().getCommentInfo() + ""));
        photoRecycleBuild.setHttpUrl(bean.getData().getExtends7());
    }
}
